package com.czy.owner.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.czy.owner.entity.MyOrderModel;
import com.czy.owner.entity.WorkOrderModel;
import com.czy.owner.ui.workorder.orderviewholder.OrderCancelledViewHolder2;
import com.czy.owner.ui.workorder.orderviewholder.OrderCommentedViewHolder2;
import com.czy.owner.ui.workorder.orderviewholder.OrderCompletedViewHolder2;
import com.czy.owner.ui.workorder.orderviewholder.OrderCreateViewHolder2;
import com.czy.owner.ui.workorder.orderviewholder.OrderPendingInServiceViewHolder;
import com.czy.owner.ui.workorder.orderviewholder.OrderPendingPaymentBanlanceViewHolder;
import com.czy.owner.ui.workorder.orderviewholder.OrderPendingPaymentViewHolder;
import com.czy.owner.ui.workorder.orderviewholder.OrderPendingServiceViewHolder;
import com.czy.owner.ui.workorder.orderviewholder.OrderWorkCancleViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderCreateViewHolder;
import com.czy.owner.ui.workorder.viewholder.OrderHadPayedViewHolder;
import com.czy.owner.utils.StringUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2016/6/14.
 */
public class OrderMultiStyleAdapter2 extends RecyclerArrayAdapter<WorkOrderModel> {
    public static final int ORDER_CREATED = 0;//待处理
    public static final int ORDER_WAITPAYDEPOSIT = 1; //d代付款，包括定金，和尾款
    public static final int ORDER_WAITSERVICE = 2;
    public static final int ORDER_INSERVICE = 3;
    public static final int ORDER_INSETTLEMENT = 4;
    public static final int ORDER_HASPAYED = 5;
    public static final int ORDER_COMPLETED = 6;
    public static final int ORDER_CANCELLED = 7;
    public static final int ORDER_COMMENTED = 8;
    public static final int DEFAULTERROR = 9;
    public static final int WORKORDERCANCLE = 10;//工单取消

    //待处理， created ，待付定金，  waitPayDeposit   ，， 待服务  waitService 服务中inService,  支付余款 inSettlement  已付尾款hasPayed,
    // 已完成completed 已评价commented,已取消cancelled，
    public static final String CREATED = "created";
    public static final String WAITPAYDEPOSIT = "waitPayDeposit";
    public static final String WAITSERVICE = "waitService";
    public static final String INSERVICE = "inService";
    public static final String INSETTLEMENT = "inSettlement";
    public static final String HASPAYED = "hasPayed";
    public static final String COMPLETED = "completed";
    public static final String CANCELLED = "cancelled";
    public static final String COMMENTED = "commented";
    public static final String ININSPECTION = "inInspection";//质检中，app显示为服务中

    private Context ctx;

    public OrderMultiStyleAdapter2(Context context) {
        super(context);
        this.ctx = context;
    }

    @Override
    public int getViewType(int position) {
        return checkDataType(getItem(position));
    }

    private int checkDataType(WorkOrderModel model) {
//待处理
        if (model.getOrderStatus().equals(CREATED)) {
            return ORDER_CREATED;
            //待付定金
        } else if (model.getOrderStatus().equals(WAITPAYDEPOSIT)) {
            return ORDER_WAITPAYDEPOSIT;
//待服务
        } else if (model.getOrderStatus().equals(WAITSERVICE)) {
            return ORDER_WAITSERVICE;
//服务中
        } else if (model.getOrderStatus().equals(INSERVICE) || model.getOrderStatus().equals(ININSPECTION)) {
            return ORDER_INSERVICE;
            //待付余款
        } else if (model.getOrderStatus().equals(INSETTLEMENT)) {
            return ORDER_INSETTLEMENT;

        } else if (model.getOrderStatus().equals(HASPAYED)) {
            return ORDER_HASPAYED;

        } else if (model.getOrderStatus().equals(COMPLETED)) {
            return ORDER_COMPLETED;

        } else if (model.getOrderStatus().equals(CANCELLED)) {
            if (StringUtils.isEmpty(model.getOpenTime() + "") || model.getOpenTime() == 0) {
                return ORDER_CANCELLED;
            }
            return WORKORDERCANCLE;

        } else if (model.getOrderStatus().equals(COMMENTED)) {
            return ORDER_COMMENTED;

        }


        return DEFAULTERROR;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        switch (viewType) {
            case ORDER_CREATED:
                return new OrderCreateViewHolder2(parent, ctx);
            case ORDER_WAITPAYDEPOSIT:
                return new OrderPendingPaymentViewHolder(parent, ctx);
            case ORDER_WAITSERVICE:
                return new OrderPendingServiceViewHolder(parent, ctx);
            case ORDER_INSERVICE:
                return new OrderPendingInServiceViewHolder(parent, ctx);
            case ORDER_INSETTLEMENT:
                return new OrderPendingPaymentBanlanceViewHolder(parent, ctx);
            case ORDER_HASPAYED:
                return new OrderCompletedViewHolder2(parent, ctx);
            case ORDER_COMPLETED:
                return new OrderCompletedViewHolder2(parent, ctx);
            case ORDER_CANCELLED:
                return new OrderCancelledViewHolder2(parent, ctx);
            case ORDER_COMMENTED:
                return new OrderCommentedViewHolder2(parent, ctx);
            case WORKORDERCANCLE:
                return new OrderWorkCancleViewHolder(parent, ctx);

            default:
                return new OrderCreateViewHolder2(parent, ctx);
        }
    }
}
